﻿Public Class ErrLogWriter
    ' James D. Zoll
    '
    ' The ErrLogWriter class will handle exceptions for DK Optimize.
    ' Whenever there is an exception the program will close, but it will
    ' write a stacktrace out to a timestamped log file in the logs directory
    ' of the application data folder.  These are written in plaintext.
    Shared Sub writeLog(ByVal ex As Exception)
        Dim fullPath As String
        Dim logNum As Integer = 1
        Dim oWrite As System.IO.StreamWriter

        fullPath = System.Windows.Forms.Application.CommonAppDataPath

        If System.IO.Directory.Exists(fullPath & "\logs") = False Then
            System.IO.Directory.CreateDirectory(fullPath & "\logs")
        End If

        While System.IO.File.Exists(fullPath & "\logs\errlog_" & logNum & ".txt") = True
            logNum += 1
        End While

        oWrite = System.IO.File.CreateText(fullPath & "\logs\errlog_" & logNum & ".txt")
        oWrite.WriteLine("Date / Time: " & Date.Today & " " & TimeOfDay)
        oWrite.WriteLine(ex.ToString)
        oWrite.Close()

    End Sub

End Class
